<template>
  <div class="title">
    <div class="name">{{ res.name }}</div>
    <div class="match">
      <div class="progress">
        <div class="bar" :style="{ width: res.match }"></div>
      </div>
      <div class="match-info">
        {{ res.match }}匹配度
      </div>
    </div>
    <div class="other">
      <div class="first">
        {{ res.similar[0] }}
      </div>
      <div class="second">
        {{ res.similar[1] }}
      </div>
    </div>
  </div>

  <div class="menu-content">
    <ul class="select">
      <li @click="change('nutrition')" :class="{ active: flag === 'nutrition' }">营养成分</li>
      <li @click="change('tips')" :class="{ active: flag === 'tips' }">健康提示</li>
      <li @click="change('storage')" :class="{ active: flag === 'storage' }">存储方法</li>
    </ul>
    <div class="content">
      <div v-if="flag === 'nutrition'" class="content-part">
        <ul>
          <li v-for="(value, key) in res.nutrition">
            <div class="part">{{ key }}</div>
            <div class="value">{{ value }}</div>
          </li>
        </ul>
      </div>
      <div v-if="flag === 'tips'" class="content-tips">
        {{ res.tips }}
      </div>
      <div v-if="flag === 'storage'" class="content-store">
        {{ res.store }}
      </div>
    </div>

  </div>

  <div class="recommend">
    <div class="topic">推荐菜谱</div>
    <div class="content-parts">
      <div @click="router.push({
        path: '/editCook',
        query: {
          dishName: item.name,
          image: item.image,
          desc: item.desc
        }
      })" v-for="item in res.recommend" class="card">
        <div class="pic">
          <img :src="item.image" :alt="item.name">
        </div>
        <div class="contents">
          <h2>{{ item.name }}</h2>
          <p>{{ item.desc }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import router from '@/router/index.js';

const flag = ref('nutrition'); // 默认显示营养成分

const change = (item) => {
  flag.value = item
}

const props = defineProps({
  data: {
    type: Object,
    default: ''
  }
})

const res = props.data
</script>

<style lang="less" scoped>
.title {
  margin: 24px 16px;
  padding: 16px;
  background: #FFFFFF;
  box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.05);
  border-radius: 12px;

  .name {
    font-weight: 500;
    font-size: 24px;
    color: #1F2937;
    margin-bottom: 14px;
  }

  .match {
    display: flex;
    align-items: center;

    .progress {
      height: 8px;
      background-color: #E5E7EB;
      border-radius: 4px;
      width: 6rem;
      overflow: hidden;

      .bar {
        background-color: #4CAF50;
        height: 100%;
      }
    }

    .match-info {
      font-weight: 400;
      font-size: 14px;
      color: #4B5563;
      margin-left: 16px;
    }
  }

  .other {
    display: flex;
    align-items: center;
    margin-top: 16px;

    div {
      padding: 8px 13px;
      background: rgba(249, 115, 22, 0.1);
      border-radius: 4px;
      border: 1px solid #E5E7EB;
      font-weight: 400;
      font-size: 14px;
      color: #F97316;
      margin-right: 8px;
    }
  }

}

.menu-content {
  background-color: #FFF;
  margin: 0 16px;
  border-bottom: 1px solid #E5E7EB;


  .select {
    display: flex;
    justify-content: space-between;

    li {
      padding: 15px 29px;
      font-weight: 400;
      font-size: 14px;
      color: #4B5563;
    }

    .active {
      color: #4CAF50;
      border-bottom: 3px solid #4CAF50;
    }
  }

  .content {
    height: 4rem;


    .content-part {
      height: 4rem;

      ul {
        padding: 16px;

        li {
          display: flex;
          justify-content: space-between;
          align-items: center;
          margin-bottom: 16px;
          font-weight: 400;
          font-size: 14px;
          color: #4B5563;
        }
      }
    }

    .content-tips {
      padding: 16px;
      height: 4rem;
      font-weight: 400;
      font-size: 14px;
      color: #4B5563;
      line-height: 22px;
      box-sizing: border-box;
    }

    .content-store {
      padding: 16px;
      height: 4rem;
      font-weight: 400;
      font-size: 14px;
      color: #4B5563;
      line-height: 22px;
      box-sizing: border-box;
    }
  }
}

.recommend {
  margin: 16px;

  .topic {
    margin-bottom: 16px;
    font-weight: 500;
    font-size: 18px;
    color: #1F2937;
  }

  .content-parts {
    display: flex;
    justify-content: space-around;

    .card {
      width: 4rem;
      background: #FFFFFF;
      padding-bottom: 16px;
      box-sizing: border-box;


      .pic {
        width: 100%;

        img {
          width: 100%;
          height: auto;
          border-radius: 12px;
        }
      }

      .contents {
        h2 {
          font-size: 0.38rem;
          color: #000000;
          font-weight: 500;
          margin: 8px 0;
          display: flex;
          align-items: center;
        }
      }

      p {
        font-weight: 400;
        font-size: 12px;
        color: #6B7280;
      }
    }
  }
}
</style>